<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
    <meta charset="UTF-8">
    <title>主页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" th:inline="javascript">
        function focus(gid) {
            $.ajax(
                {
                    //请求路径，要注意的是url和th:inline="javascript"
                    url: [[@{/cart/focus
                }
        ]],
            //请求类型
            type : "post",
                contentType
        :
            "application/json",
                //data表示发送的数据
                data
        :
            JSON.stringify({
                id: gid
            }),
                //成功响应的结果
                success
        :

            function (obj) {//obj响应数据
                if (obj == "no") {
                    alert("您已收藏该商品！");
                } else if (obj == "ok") {
                    alert("成功收藏该商品");
                } else {
                    alert("您没有登录，请登录！");
                }
            }

        ,
            error : function () {
                alert("处理异常！");
            }
        }
        )
            ;
        }
    </script>
</head>
<body>
    <!-- 加载header.html -->
    <div th:include="user/header"></div>
    <div class="container">
        <div>
            <h4>搜索结果</h4>
        </div>
        <div class="row">
            <div class="col-xs-6 col-md-2" th:each="rGoods:${searchgoods}">
                <a th:href="'goodsDetail?id=' + ${rGoods.id}" class="thumbnail"> <img
                        alt="100%x180" th:src="${rGoods.gpicture}"
                        style="height: 180px; width: 100%; display: block;">
                </a>
                <div class="caption" style="text-align: center;">
                    <div>
                        <span th:text="${rGoods.gname}"></span>
                    </div>
                    <div>
						<span style="color: red;">&yen;
							<span th:text="${rGoods.grprice}"></span>
						</span>
                        <span class="text-dark" style="text-decoration: line-through;"> &yen;
							<span th:text="${rGoods.goprice}"></span>
						</span>
                    </div>
                    <a th:href="'javascript:focus('+ ${rGoods.id} +')'" class="btn btn-primary"
                       style="font-size: 10px;">加入收藏</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
